package com.example.com.common.view.dialog;



import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

import com.example.com.common.R;

public class MessageDialog extends BaseDialog {

	View.OnClickListener mListener;
	private CharSequence message, title;

	public MessageDialog(Context context, CharSequence message, String title) {
		super(context, R.style.translucentDialog);
		this.message = message;
		this.title = title;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.dialog_message);
		if (!TextUtils.isEmpty(title)) {
			((TextView) findViewById(R.id.tv_dialog_title)).setText(title);
		}else{
			findViewById(R.id.tv_dialog_title).setVisibility(View.GONE);
			findViewById(R.id.dialog_title_line).setVisibility(View.GONE);
		}
		((TextView) findViewById(R.id.tv_dialog_content)).setText(message);
		findViewById(R.id.btn_close).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						if(mListener!=null){
							mListener.onClick(v);
						}
						dismiss();
					}
				});

		findViewById(R.id.linear_outside).setOnTouchListener(
				new OnTouchListener() {

					@Override
					public boolean onTouch(View v, MotionEvent event) {
						if(canceledOnTouchOutside)
							dismiss();
						return false;
					}
				});
	}
	private boolean canceledOnTouchOutside = true;
	@Override
	public void setCanceledOnTouchOutside(boolean cancel) {
		this.canceledOnTouchOutside = cancel;
	}

	public void setCallBack(View.OnClickListener listener){
		mListener=listener;
	}

}
